namespace SimpleWebServices.Models
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class CoordinatesFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Coordinates>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("coordinates")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Coordinates actual = "<coordinates latitude='53.493192' longitude='-2.105470' />".Deserialize<Coordinates>();

            Assert.Equal<decimal>(53.493192m, actual.Latitude);
            Assert.Equal<decimal>(-2.105470m, actual.Longitude);
        }

        [Fact]
        public void deserializeEmpty()
        {
            Coordinates actual = "<coordinates />".Deserialize<Coordinates>();

            Assert.Equal<decimal>(0, actual.Latitude);
            Assert.Equal<decimal>(0, actual.Longitude);
        }

        [Fact]
        public void serialize()
        {
            Coordinates obj = new Coordinates
            {
                Latitude = 53.493192m,
                Longitude = -2.105470m
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/coordinates[@latitude='53.493192'][@longitude='-2.105470'])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Coordinates());
        }

        [Fact]
        public void prop_Latitude()
        {
            Assert.True(new PropertyExpectations(typeof(Coordinates).GetProperty("Latitude"))
                .XmlAttribute("latitude")
                .IsAutoProperty<decimal>()
                .Result);
        }

        [Fact]
        public void prop_Longitude()
        {
            Assert.True(new PropertyExpectations(typeof(Coordinates).GetProperty("Longitude"))
                .XmlAttribute("longitude")
                .IsAutoProperty<decimal>()
                .Result);
        }
    }
}